package com.csii.pe.dynamic.workflow;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;

public class test {

	public static void readTxtFileForQQ3(String filePath,String search) throws Exception {
        try {
            String encoding="UTF-8";
            File file=new File(filePath);
            if(file.isFile() && file.exists()){ 
                InputStreamReader read = new InputStreamReader(
                        new FileInputStream(file),encoding);
                BufferedReader bufferedReader = new BufferedReader(read);
                String lineTxt = null;
                String qqName = "";
                while((lineTxt = bufferedReader.readLine()) != null){
                    if(!lineTxt.equals("")){
                        if(!checkNumber(lineTxt.trim())){

                            if(lineTxt.length() > 20){
                                String[] lineTxts = lineTxt.split("\\s+");
                                Connection con = dbUtil.getConnection(); 
                                String sql = "insert into qqnum2 values(?,?,?,?,?,now(),1,?)";
                                PreparedStatement pstmt = con.prepareStatement(sql);
                                //id,name,qq,sex,age,creatime,status
                                pstmt.setString(1, UUID.randomUUID().toString());
                                pstmt.setString(2, qqName);
                                pstmt.setString(3, lineTxts[0]);
                                pstmt.setString(4, lineTxts[1]);
                                pstmt.setString(5, lineTxts[2]);
                                pstmt.setString(6, search);
                                int result = pstmt.executeUpdate();
                                dbUtil.closeResources(con, pstmt, null);
                                if(result==1){
                                    System.out.println("添加成功！");
                                }else{
                                    System.out.println("添加失败！");
                                }
                            }else{
                                qqName = new String(lineTxt.getBytes("gb2312"),"gbk");
                            }
                        }
                    }
                }
                read.close();
            }else{
                throw new Exception("找不到指定的文件");
            }
        } catch (Exception e) {
            throw new Exception("读取文件内容出错");
        }
    }

}
